<?php
namespace Home\Controller;
use Think\Controller;
class ModelController extends Controller {
    public function index(){
        M()->execute('TRUNCATE TABLE model_post');
        $model = D('Article');
        $this->show('添加数据..<br>');
        $model->add($model->create(array('title'=>'文章1','content'=>'内容1')));
        $model->add($model->create(array('title'=>'文章2','content'=>'内容2')));
        $this->show('添加完后的数据：<br>');
        $all = $model->select();
        dump($all);
        $this->show('更新数据1：<br>');
        sleep(1);
        $model->save($model->create(array('id'=>1,'content'=>'内容1修改')));
        $this->show('更新后数据1：');
        dump($model->find(1));
        $this->show('删除数据2：<br>');
        $model->delete(2);
        $this->show('删除后的全部数据为：<br>');
        dump($model->select());
        $this->show('演示模型功能完毕');
    }
}